//
//  ActivityCallupDetailViewController.m
//  wtshoppingcite
//
//  Created by Baojia-LC on 14/11/10.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "ActivityCallupDetailViewController.h"
#import "CustomSortButtonView.h"
#import "NetServiseCommonData.h"
#import "UIImageView+WebCache.h"
@interface ActivityCallupDetailViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView* tableView;
@property(nonatomic,strong)UIScrollView* scrollView;
@property(nonatomic,strong)UIView* headerInfoView;
@property(nonatomic,strong)UIView* organizerView;
@property(nonatomic,strong)UIView* actNumberTimeView;
@property(nonatomic,strong)NSArray* commentArray;
@property(nonatomic,strong)NSDictionary* actInfoData;
@end

@implementation ActivityCallupDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitleView:@"活动详情"];
    [self setRightButton:@"举报" sel:@selector(report:) viewController:self];
    
    //    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    //    _tableView.delegate = self;
    //    _tableView.dataSource = self;
    //    [self.view addSubview:_tableView];
    
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_scrollView];
    
    [self createActivityInfoSubView];
    [self createSendUpPeopleView];
    [self createActNumberTimeView];
    
    _scrollView.height = _headerInfoView.height+_organizerView.height+_actNumberTimeView.height;
    
    [self startRequestData];
    
}

-(void)startRequestData{
    
    NSDictionary* data = [NetServiseCommonData getActivityCallupListData];
    NSDictionary* detailDic = data[@"detailinfo"];
    _actInfoData =  detailDic;
    [self freshActInfoData:detailDic];
    
}

-(void)freshActInfoData:(NSDictionary*)data{
    
    //headerinfoData
    UIImageView* actIconView = (UIImageView*)[_headerInfoView viewWithTag:100];
    UILabel* typeLabel = (UILabel*)[_headerInfoView viewWithTag:101];
    UILabel* titleLabel = (UILabel*)[_headerInfoView viewWithTag:102];
    UILabel* timeLabel = (UILabel*)[_headerInfoView viewWithTag:103];
    UILabel* addressLabel = (UILabel*)[_headerInfoView viewWithTag:104];
    
    NSString* iconimage = ObjToString(data[@"image"]);
    [actIconView setImageWithURL:[NSURL URLWithString:iconimage]];
    
    NSString* type = ObjToString(data[@"type"]);
    if([type isEqualToString:@"最热"]){
        typeLabel.backgroundColor = COLOR_RGB(245, 88, 141);
    }else{
        typeLabel.backgroundColor = MAIN_GRAY_COLOR;
    }
    typeLabel.text = type;
    
    NSString* title = ObjToString(data[@"title"]);
    titleLabel.text = title;
    
    NSString* time = ObjToString(data[@"time"]);
    timeLabel.text = time;
    
    NSString* address = ObjToString(data[@"address"]);
    addressLabel.text = address;
    
    //organizerData
    UIImageView* nickImageView = (UIImageView*)[_organizerView viewWithTag:200];
    UILabel* nickNameLabel = (UILabel*)[_organizerView viewWithTag:201];
    
    
    NSString* userimage = ObjToString(data[@"iconimage"]);
    [nickImageView setImageWithURL:[NSURL URLWithString:userimage]];
    
    NSString* nickname = ObjToString(data[@"orgrizor"]);
    nickNameLabel.text = nickname;
    
    
    //ActNumberTimeData
    UILabel* endDateLabel = (UILabel*)[_actNumberTimeView viewWithTag:300];
    UIButton* statusButton = (UIButton*)[_actNumberTimeView viewWithTag:301];
    UILabel* limitLabel = (UILabel*)[_actNumberTimeView viewWithTag:302];
    
    NSString* endTime = ObjToString(data[@"endtime"]);
    NSString* acttype = ObjToString(data[@"acttype"]);
    NSString* limittype = ObjToString(data[@"limittype"]);
    NSString* vistorNum = ObjToString(data[@"visitornum"]);
    endDateLabel.text = [NSString stringWithFormat:@"报名截止:%@",endTime];
    [statusButton setTitle:acttype forState:UIControlStateNormal];
    limitLabel.text = [NSString stringWithFormat:@"限制人数:%@   已报名:%@",limittype,vistorNum];
}

-(void)createActivityInfoSubView{
    
    _headerInfoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 80)];
    [_scrollView addSubview:_headerInfoView];
    
    UIImageView* actIconView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 50, 60)];
    actIconView.backgroundColor = [UIColor grayColor];
    actIconView.tag = 100;
    [_headerInfoView addSubview:actIconView];
    
    UILabel* typeLabel = [self createLabelWithFrame:CGRectMake(actIconView.right +10, actIconView.top, 50, 18) text:@"" font:14 textAli:NSTextAlignmentCenter textColor:[UIColor whiteColor]];
    typeLabel.tag = 101;
    [_headerInfoView addSubview:typeLabel];
    
    UILabel* titleLabel = [self createLabelWithFrame:CGRectMake(typeLabel.right, typeLabel.top, 220, 18) text:@"" font:14 textAli:NSTextAlignmentLeft textColor:COLOR_RGB(95, 95, 95)];
    titleLabel.tag = 102;
    [_headerInfoView addSubview:titleLabel];
    
    UIImageView* timeView = [[UIImageView alloc] initWithFrame:CGRectMake(typeLabel.left, titleLabel.bottom+8, 20, 20)];
    timeView.image = [UIImage imageNamed:@"time"];
    [_headerInfoView addSubview:timeView];
    
    UILabel* timeLabel = [self createLabelWithFrame:CGRectMake(timeView.right+2, titleLabel.bottom+8, 240, 18) text:@"" font:14 textAli:NSTextAlignmentLeft textColor:COLOR_RGB(95, 95, 95)];
    timeLabel.tag = 103;
    [_headerInfoView addSubview:timeLabel];
    
    
    UIImageView* addrView = [[UIImageView alloc] initWithFrame:CGRectMake(typeLabel.left, timeLabel.bottom+3, 20, 20)];
    addrView.image = [UIImage imageNamed:@"address"];
    [_headerInfoView addSubview:addrView];
    
    UILabel* addressLabel = [self createLabelWithFrame:CGRectMake(addrView.right+2, timeLabel.bottom+3, SCREEN_WIDTH, 18) text:@"" font:12 textAli:NSTextAlignmentLeft textColor:COLOR_RGB(95, 95, 95)];
    addressLabel.tag = 104;
    [_headerInfoView addSubview:addressLabel];
    
    UIImageView* line = [[UIImageView alloc] initWithFrame:CGRectMake(15, _headerInfoView.bottom, SCREEN_WIDTH, 1)];
    line.backgroundColor = COLOR_RGB(222, 222, 222);
    [_headerInfoView addSubview:line];
    
}

//发起人
-(void)createSendUpPeopleView{
    
    _organizerView = [[UIView alloc] initWithFrame:CGRectMake(0, _headerInfoView.bottom + 5, SCREEN_WIDTH, 90)];
    [_scrollView addSubview:_organizerView];
    
    UIImageView* iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 30, 30)];
    iconImageView.backgroundColor = [UIColor orangeColor];
    iconImageView.tag = 200;
    [_organizerView addSubview:iconImageView];
    
    UILabel* organizorLabel = [self createLabelWithFrame:CGRectMake(iconImageView.right+10, iconImageView.top+5, 140, 20) text:@"发起人" font:14 textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
    organizorLabel.tag = 201;
    [_organizerView addSubview:organizorLabel];
    
    UIButton* phoneButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 50, 5, 30, 30)];
    [phoneButton setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [phoneButton setImage:[UIImage imageNamed:@"tel"] forState:UIControlStateNormal];
    [phoneButton addTarget:self action:@selector(phoneClick:) forControlEvents:UIControlEventTouchUpInside];
    phoneButton.tag = 202;
    [_organizerView addSubview:phoneButton];
    
    UILabel* actPhotoNumberLabel = [self createLabelWithFrame:CGRectMake(0, iconImageView.bottom+5, SCREEN_WIDTH, 30) text:@"晒晒你的活动照片吧!(0张)" font:14 textAli:NSTextAlignmentCenter textColor:MAIN_GRAY_COLOR];
    actPhotoNumberLabel.backgroundColor = COLOR_RGB(213, 213, 213);
    actPhotoNumberLabel.tag = 203;
    [_organizerView addSubview:actPhotoNumberLabel];
    
    UILabel* actInfoStaticLabel = [self createLabelWithFrame:CGRectMake(10, actPhotoNumberLabel.bottom+5, 120, 20) text:@"活动详情" font:14 textAli:NSTextAlignmentLeft textColor:MAIN_GRAY_COLOR];
    [_organizerView addSubview:actInfoStaticLabel];
    
    UIImageView* line = [[UIImageView alloc] initWithFrame:CGRectMake(15, actInfoStaticLabel.bottom+5, SCREEN_WIDTH, 1)];
    line.backgroundColor = COLOR_RGB(222, 222, 222);
    [_organizerView addSubview:line];
}

-(void)createActNumberTimeView{
    
    _actNumberTimeView = [[UIView alloc] initWithFrame:CGRectMake(0, _organizerView.bottom + 15, SCREEN_WIDTH, 180)];
    [_scrollView addSubview:_actNumberTimeView];
    
    UILabel* endDateLabel = [self createLabelWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 20) text:@"报名截止:" font:12 textAli:NSTextAlignmentCenter textColor:MAIN_GRAY_COLOR];
    endDateLabel.tag = 300;
    [_actNumberTimeView addSubview:endDateLabel];
    
    UIButton* statusButton = [[UIButton alloc] initWithFrame:CGRectMake(50, endDateLabel.bottom+4, SCREEN_WIDTH - 2*50, 35)];
    [statusButton setBackgroundColor:COLOR_RGB(182, 177, 178)];
    [statusButton setTitle:@"活动已结束" forState:UIControlStateNormal];
    [statusButton.layer setCornerRadius:5];
    statusButton.clipsToBounds = YES;
    statusButton.tag = 301;
    [_actNumberTimeView addSubview:statusButton];
    
    UILabel* limitNumberLabel = [self createLabelWithFrame:CGRectMake(0, statusButton.bottom+5, SCREEN_WIDTH, 20) text:@"" font:12 textAli:NSTextAlignmentCenter textColor:MAIN_GRAY_COLOR];
    limitNumberLabel.tag = 302;
    [_actNumberTimeView addSubview:limitNumberLabel];
    
    UIImageView* line = [[UIImageView alloc] initWithFrame:CGRectMake(15, limitNumberLabel.bottom+2, SCREEN_WIDTH, 1)];
    line.backgroundColor = COLOR_RGB(222, 222, 222);
    [_actNumberTimeView addSubview:line];
    
    CustomSortButtonView* customItemView = [[CustomSortButtonView alloc] initWithFrame:CGRectMake(0, line.bottom+1, SCREEN_WIDTH, 45)];
    customItemView.tag = 303;
    [customItemView initWithItemNames:@[@"0评论",@"分享"] itemImages:@[@"pinglun",@"home_share"]];
    [_actNumberTimeView addSubview:customItemView];
//    customItemView.block = ^(UIButton* button,int index){
//        
//    };
}


-(void)phoneClick:(UIButton*)button{
    
}


-(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString* indentify = @"cell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:indentify];
    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentify];
    }
    return cell;
}

-(void)report:(UIButton*)button{
    
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    ;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
